package com.example.lawyermanager.dangao.controller;

import com.example.lawyermanager.dangao.entity.Lawyer;
import com.example.lawyermanager.dangao.service.LawyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 律师控制器
 * @author 86134
 * @version 1.0
 */
@Controller
public class LawyerController {
    @Autowired
    LawyerService lawyerService;

    @RequestMapping("/updata")
    public String updataLawyer(Lawyer lawyer){
        lawyerService.updataLawyer(lawyer);
//        return "../static/success";
        return "redirect:/show";
    }

    @RequestMapping("/get")
    public String findLawyer(Model model,int lawyerid){
        Lawyer lawyer = lawyerService.findLawyer(lawyerid);
        model.addAttribute("lawyer",lawyer);
        return "../static/updLawyer.html";
    }

    @RequestMapping("/del")
    public String delLawyer(int lawyerid){
        lawyerService.removeLawyer(lawyerid);
        return "redirect:/show";
    }

    @RequestMapping("/show")
    public String showLawyer(Model model){
        List<Lawyer> lawyerList = lawyerService.findLawyer();
        model.addAttribute("lawyerList",lawyerList);
        return "../static/displayLawyer";
    }

    @RequestMapping("/addLawyer")
    public String addLawyer(Lawyer lawyer){
        lawyerService.addLawyer(lawyer);
        return "../static/success";
    }
}
